#include <stdio.h>
#include <assert.h>
#include <sparrow/types.h>
#include <sparrow/util.h>

#include "test_helpers.h"

void test()
{
    Octets join_result;
    join(join_result, ",", "a", "b", "c", NULL);
    assert(join_result == make_octets("a,b,c"));
    std::vector<Octets> split_result;
    split(split_result, join_result, ",");
    assert(split_result[0] == make_octets("a"));
    assert(split_result[1] == make_octets("b"));
    assert(split_result[2] == make_octets("c"));

    assert(join(join_result, ",", NULL) == Octets());
    split(split_result, join_result, ",");
    assert(split_result[0] == Octets());

    assert(join(join_result, ",", "", NULL) == make_octets(""));
    split(split_result, join_result, ",");
    assert(split_result[0] == make_octets(""));

    assert(join(join_result, ",", "", "", NULL) == make_octets(","));
    split(split_result, join_result, ",");
    assert(split_result[0] == make_octets(""));
    assert(split_result[1] == make_octets(""));
}

void test2()
{
    Octets buff = make_octets("abcdefgh");
    Slice allbuff(buff, buff.begin(), buff.end());
    std::string h;

    assert(head(buff, 40) == "abcdefgh");
    assert(head(allbuff, 40) == "abcdefgh");

    assert(head(buff, 4) == "abcd");
    assert(head(allbuff, 4) == "abcd");

    assert(tail(buff, 40) == "abcdefgh");
    assert(tail(allbuff, 40) == "abcdefgh");

    assert(tail(buff, 4) == "efgh");
    assert(tail(allbuff, 4) == "efgh");
}

int main(int argc, char **argv)
{
    test();
    test2();
    return 0;
}

